package cn.zyq.ykb.controller.mgt.product;

import cn.zyq.ykb.beans.product.ProductOrder;
import cn.zyq.ykb.service.product.ProductOrderService;
import cn.zyq.ykb.system.annotation.Log;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.common.PageParam;
import cn.zyq.ykb.system.ry.enums.BusinessType;
import cn.zyq.ykb.system.ry.util.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品订单Controller
 *
 * @author SystemAuth
 * @date 2023-11-02
 */

@RestController(value = "MgtProductOrderController")
@RequestMapping("/mgt/productOrder")
@Api(tags = "商品订单接口")
public class ProductOrderController extends BaseController {

    @Autowired
    private ProductOrderService productOrderService;

    /**
     * 查询商品订单列表
     */
    @ApiOperation(value = "列表", response = ProductOrder.class)
    @PostMapping("/list")
    public Object list(@RequestBody PageParam pageParam) {
        return this.productOrderService.selectProductOrderListGL(pageParam );
    }

     /**
      * 导出商品订单列表
      */
     @ApiOperation(value = "导出")
     @Log(title = "商品订单" , businessType = BusinessType.EXPORT)
     @PostMapping("/export")
     public void export(HttpServletResponse response, @RequestBody PageParam pageParam) {
         List<ProductOrder> list = productOrderService.selectProductOrderAllList(pageParam);
         ExcelUtil<ProductOrder> util = new ExcelUtil<ProductOrder>(ProductOrder. class);
         util.exportExcel(response, list, "商品订单数据");
     }

    /**
     * 获取商品订单详细信息
     */
    @ApiOperation(value = "详情", response = ProductOrder.class)
    @GetMapping(value = "/{productOrderID}")
    public Object getInfo(@PathVariable("productOrderID") Integer productOrderID) {
        return this.productOrderService.selectProductOrderByProductOrderID(productOrderID);
    }
    /**
     * 获取商品订单详细信息
     */
    @ApiOperation(value = "详情", response = ProductOrder.class)
    @GetMapping(value = "/detail/{serviceID}")
    public Object getInfo(@PathVariable(value = "serviceID") String serviceID) {
        return this.productOrderService.selectProductOrderByServiceID(serviceID);
    }

    /**
     * 新增商品订单
     */
    @ApiOperation(value = "新增")
    @Log(title = "商品订单", businessType = BusinessType.INSERT)
    @PostMapping
    public Object add(@RequestBody ProductOrder productOrder) {
        return this.productOrderService.insertProductOrder(productOrder);
    }

    /**
     * 修改商品订单
     */
    @ApiOperation(value = "编辑")
    @Log(title = "商品订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public Object edit(@RequestBody ProductOrder productOrder) {
        return this.productOrderService.updateProductOrder(productOrder);
    }

    /**
     * 删除商品订单
     */
    @ApiOperation(value = "删除")
    @Log(title = "商品订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{productOrderIDs}")
    public Object remove(@PathVariable Integer[] productOrderIDs) {
        return this.productOrderService.deleteProductOrderByProductOrderIDs(productOrderIDs);
    }
}
